<template>
    <!-- <van-pull-refresh v-model="isLoading" @refresh="onRefresh"> -->
        <!-- 表格 -->
        <div class="DataManagement">
            <div class="main_topWarp">
                <div class="DataManagement_back" >
                    <span class="DataManagement_title">浏览</span>
                    </div>
            </div>
            <div class="DataManagement_main">
                <div>
                    <van-collapse v-model="activeNames">
                        <van-cell-group>
                            <van-collapse-item title="数据报表" name="1" class="datatitle_style">
                                <!-- <van-cell v-if="dataReporting.length>0"  @click="toOtherPage(item.ID,3,item.ShareName)" class="datamain_style" v-for="item in dataReporting" :key="item.ID" :title="item.ShareName"  is-link /> -->
                                <van-cell v-if="dataReporting.length>0"  @click="toOtherPage(item.id,3,item.name)" class="datamain_style" v-for="item in dataReporting" :key="item.id" :title="item.name"  is-link />
                                <van-cell v-else>暂无数据</van-cell>
                            </van-collapse-item>
                        </van-cell-group>
                    </van-collapse>

                    <van-collapse v-model="activeNames">
                        <van-cell-group>
                            <van-collapse-item title="数据看板" name="2"  class="datatitle_style">
                                <!-- <van-cell v-if="dataManagement.length>0" @click="toOtherPage(item.ID,4,item.ShareName)" class="datamain_style" v-for="item in dataManagement" :key="item.ID" :title="item.ShareName"  is-link /> -->
                                <van-cell v-if="StoryboardData.length>0" @click="toOtherPage(item.id,4,item.name)" class="datamain_style" v-for="item in StoryboardData" :key="item.id" :title="item.name"  is-link />
                                <van-cell v-else>暂无数据</van-cell>
                            </van-collapse-item>
                        </van-cell-group>
                    </van-collapse>
                </div>

            </div>
        </div>
    <!-- </van-pull-refresh> -->
</template>

<script>
import { onMounted, reactive, ref, toRefs } from 'vue'
import { Toast, Notify} from 'vant';
import { useStore } from "vuex"; // ⚪️ 引入状态管理
import router from "@/router";
import { ShareInfoGetMainList } from "@/network/DataManagement.js";
import { StoryBoardGetAllStoryboard} from "@/network/StoryBoard.js";

export default {
    setup() {
        const state = reactive({
            isLoading: false,
            // =====
            list: [],
            dataReporting:[],
            dataManagement:[],
            loading: false,
            finished: false,
            activeNames: ['1','2'],
            StoryboardData:[]
        })
        onMounted(() => {
            getInitDataList()
        });
        // 获取首页填报页列表数据
        const getInitDataList=()=>{
            state.loading = true;
            // ShareInfoGetMainList().then((res)=>{
            //     console.log('res',res);
            //     state.list=res.data
            //     state.dataReporting = res.data.filter(item => item.ShareSort === "数据报表");
            //     // state.dataReporting = res.data.filter(item => item.ShareSort === "数据填报");
            //     // state.dataManagement = res.data.filter(item => item.ShareSort === "数据看板");
            // })
            
            // 获取登录用户对应的所有故事板列表信息
            StoryBoardGetAllStoryboard().then((res)=>{
                // state.list=res.data
                state.dataReporting = res.data.filter(item => item.type === "数据报表");
                state.StoryboardData = res.data.filter(item => item.type === "移动端看板");
                // state.StoryboardData=res.data
            })
        } 
        // 下拉刷新
        const onRefresh = () => {
            getInitDataList()
            state.isLoading = false
        }

        const toOtherPage=(Id, type,shareName)=>{
            if (type==3) {
                router.push({
                    name: 'DataReportForms', // 路由名称
                    query: { // 传递参数
                        Id: Id,
                        type: type,
                        shareName:shareName
                    }
                });
            }
            else if (type==4) {
                router.push({
                    name: 'dataBoard', // 路由名称
                    query: { // 传递参数
                        Id: Id,
                        type: type,
                        shareName:shareName
                    }
                });
            }
            
        }
        return {
            ...toRefs(state),
            onRefresh,
            toOtherPage
        };
    },
};
</script>

<style scoped></style>